<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="header.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="${path}/user?method=insert" method="post">
		用户名: <input type="text" name="name"/><br/>
		密码: <input type="password" name="password"/><br/>
		邮箱: <input type="text" name="email"/><br/>
		年龄: <input type="text" name="age"/><br/>
		部门: <select id="departmentId" name="departmentId">
				<option>---请选择 ---</option>
			</select>
			<br/>
		 <input type="submit" value="添加"/><br/>
	</form>
	
	<script type="text/javascript">
		$(function() {
			$.post('${path}/department?method=selectAllByJson',
					function(jsonObj) {
						console.log(jsonObj);
						$(jsonObj).each(function() {
							// [{…}, {…}, {…}]
							// {id: 1, name: "软件部"}
							$('#departmentId').append('<option value="'+this.id+'">'+this.name+'</option>');
						});
					},
					'json'
			);
		});
	
	</script>
</body>
</html>